package org.come.Jpanel;

import java.awt.Dimension;
import java.awt.Graphics;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.tool.btn.*;
import org.cbg.btn.TrslationBtn;
import org.come.mouslisten.TransmuteMouslisten;
import org.come.mouslisten.WLLMouslisten;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.Util;

import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



public class RuneOperateJpanel extends JPanel {

    private TrslationBtn btnSj,// 饰品升级
            btnCz;// 饰品重铸
    private GoodPanelBtn clearAll; //当前整理背包
    private BigDecimal money = new BigDecimal(0);// 消耗金钱
    private DazaoBtn perBtn1; // 重铸
    private RuneOPerBtn perBtn2;// 重铸规则
    private JLabel[] GoodsListLabel = new JLabel[31]; // 用来存放24个物品表格
    // 放置6个背包切换按钮
    private goodbtn[] btnrights;

    private JLabel labResult; // 升级结果

    private int runeType = 1;

    public RuneOperateJpanel() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
    		this.setPreferredSize(new Dimension(392, 505));
            this.setBackground(UIUtils.Color_BACK);
            this.setLayout(null);
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 70);
            offBtn.setBounds(392 - 37, 10, 25, 25);
            this.add(offBtn);
            // 饰品升级
            btnSj = new TrslationBtn("skin/8100226/button/B183.png", 1, 2, this);
            btnSj.setBounds(103 + 22, 31 - 15, 70, 35);
            this.add(btnSj);
            // 饰品重铸
            btnCz = new TrslationBtn("skin/8100226/button/B186.png", 1, 1, this);
            btnCz.setBounds(31 + 22, 31 - 15, 70, 35);
            this.add(btnCz);

            // 重铸
            perBtn1 = new DazaoBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "重铸", this);
            perBtn1.setBounds(251 + 23, 253 - 13, 59, 24);
            this.add(perBtn1);
            // 重铸规则
            perBtn2 = new RuneOPerBtn("skin/8100226/button/49.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "重铸规则", 3);
            perBtn2.setBounds(250 + 23, 217 - 13, 68, 17);
            this.add(perBtn2);

            // 升级结果
            labResult = new JLabel();
            labResult.setBounds(153 + 23, 183 - 13, 53, 51);
            labResult.setVisible(false);
            this.add(labResult);

            // 存放物品的表格1~24
            for (int i = 0; i < GoodsListLabel.length; i++) {
                int row = i % 6;
                int col = i / 6;
                GoodsListLabel[i] = new JLabel();
                GoodsListLabel[i].addMouseListener(new TransmuteMouslisten(i, this));
                if (i == 24) {
                    GoodsListLabel[i].setBounds(153 + 23, 111 - 13, 53, 51);
                } else if (i == 25) {
                    GoodsListLabel[i].setBounds(153 + 23, 183 - 13, 53, 51);
                } else if (i > 25) {
                    GoodsListLabel[i].setBounds(39 + 23 + (i - 26) * 57, 111 - 13, 53, 51);
                    GoodsListLabel[i].setVisible(false);
                } else {
                    GoodsListLabel[i].setBounds(25 + 23 + row * 51, 296 - 13 + col * 51, 49, 49);
                }
                this.add(GoodsListLabel[i]);
            }

            // 背包四个页数的按钮
            btnrights = new goodbtn[6];
            for (int i = 0; i < btnrights.length; i++) {
                btnrights[i] = new goodbtn("skin/8100226/button/" + (i + 41) + ".png", 0, this, i);
                btnrights[i].setBounds(331 + 23, 296 - 13 + i * 35, 39, 31);
                this.add(btnrights[i]);
            }
        }else {
            this.setPreferredSize(new Dimension(392, 505));
            this.setBackground(UIUtils.Color_BACK);
            this.setLayout(null);
            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 70);
            offBtn.setBounds(365, 0, 23, 23);
            this.add(offBtn);
            // 饰品升级
            btnSj = new TrslationBtn("img/xy2uiimg/升级按钮-W：30-H：138.png", 1, 2, this);
            btnSj.setBounds(3, 174, 30, 46);
            this.add(btnSj);
            // 饰品重铸
            btnCz = new TrslationBtn("img/xy2uiimg/重洗按钮2-W：30-H：138.png", 1, 1, this);
            btnCz.setBounds(3, 225, 30, 46);
            this.add(btnCz);

            // 重铸
            perBtn1 = new DazaoBtn("inkImg/hongmu/6026.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY88, "重铸", this);
            perBtn1.setBounds(251 + 38, 110, 60, 26);
            this.add(perBtn1);
            // 重铸规则
            perBtn2 = new RuneOPerBtn("inkImg/hongmu/a7.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "重铸规则", 3);
            perBtn2.setBounds(250 + 31, 143, 68, 17);
            this.add(perBtn2);

            // 升级结果
            labResult = new JLabel();
            labResult.setBounds(153 + 23, 183 - 13, 53, 51);
            labResult.setVisible(false);
            this.add(labResult);

            clearAll = new GoodPanelBtn("inkImg/hongmu/a3.png", 1, "整");
            clearAll.addMouseListener(new WLLMouslisten(17));
            clearAll.setBounds(365, 460, 17, 17);
            this.add(clearAll);


            // 存放物品的表格1~24
            for (int i = 0; i < GoodsListLabel.length; i++) {
                int row = i % 6;
                int col = i / 6;
                GoodsListLabel[i] = new JLabel();
                GoodsListLabel[i].addMouseListener(new TransmuteMouslisten(i, this));
                if (i == 24) {
                    GoodsListLabel[i].setBounds(115, 48, 53, 51);
                } else if (i == 25) {
                    GoodsListLabel[i].setBounds(229,  48, 53, 51);
                } else if (i > 25) {
                    GoodsListLabel[i].setBounds(15 + 38 + (i - 26) * 57, 48, 53, 51);
                    GoodsListLabel[i].setVisible(false);
                } else {
                    GoodsListLabel[i].setBounds(15 + 23 + row * 51, 200 - 13 + col * 51, 49, 49);
                }
                this.add(GoodsListLabel[i]);
            }

            // 背包六个页数的按钮
            btnrights = new goodbtn[6];
            for(int i = 0; i < this.btnrights.length; ++i) {
                this.btnrights[i] = new goodbtn("img/xy2uiimg/44_png.button.tab_pak.png", 0, this, i);
                this.btnrights[i].setBounds(341, 173 + i * 51, 16, 49);
                this.add(this.btnrights[i]);
            }
        }
    }

    /** 切换按钮面板 */
    public void changRuneType() {
        for (int i = 24; i < GoodsListLabel.length; i++) {
            if (i < 26) {
                GoodsListLabel[i].setVisible(runeType == 1);
                TransmuteMouslisten.goods3[i - 24] = null;
            } else {
                GoodsListLabel[i].setVisible(!(runeType == 1));
                TransmuteMouslisten.goods4[i - 26] = null;
            }
            GoodsListLabel[i].setIcon(null);
        }
        labResult.setVisible(!(runeType == 1));
        money = new BigDecimal("0");
    }

    /**
     * 重置可用按钮类型
     */
    public void btntype(int path) {
        for (int i = 0; i < path; i++) {
            btnrights[i].btntypechange(2);
        }
    }

    private ImageIcon iconBack;
    private ImageIcon icon;
    private ImageIcon icon2;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            // 背景
            if (iconBack == null) {
                iconBack = new ImageIcon("inkImg/background/S93.png");
            }
            g.drawImage(iconBack.getImage(), 0, 0, 392, 505, this);
            // 根据标识获取
            if (runeType == 1) {
                if (icon == null) {
                    icon = new ImageIcon("inkImg/background/S95.png");
                }
                g.drawImage(icon.getImage(), 46, 50, 310, 230, this);
            } else {
                if (icon2 == null) {
                    icon2 = new ImageIcon("inkImg/background/S94.png");
                }
                g.drawImage(icon2.getImage(), 46, 50, 310, 230, this);
            }

            // 画物品的图片和数量
            GoodsListFromServerUntil.draw(g, 25 + 23, 296 - 13);
            // 画现金
            Util.drawMoney(g, 124 + 23, 282 - 13);
            // 画消耗金钱
            if (money != null) {
                Util.drawPrice(g, money, 124 + 23, 262 - 13);
            }
        }else {
            // 背景
            if (iconBack == null) {
                iconBack = new ImageIcon("img/xy2uiimg/S93.png");
            }
            g.drawImage(iconBack.getImage(), 0, 0, 392, 505, this);
            // 根据标识获取
            if (runeType == 1) {
                if (icon == null) {
                    icon = new ImageIcon("img/xy2uiimg/S95.png");
                }
                g.drawImage(icon.getImage(), 33, 35, 324, 128, this);
            } else {
                if (icon2 == null) {
                    icon2 = new ImageIcon("img/xy2uiimg/S94.png");
                }
                g.drawImage(icon2.getImage(), 33, 35, 324, 128, this);
            }

            // 画物品的图片和数量
            GoodsListFromServerUntil.draw(g, 32, 174);
            // 画现金
            Util.drawMoney(g, 98, 146);
            // 画消耗金钱
            if (money != null)
                Util.drawPrice(g, money, 98, 122);
        }
    }

    public TrslationBtn getBtnSj() {
        return btnSj;
    }

    public void setBtnSj(TrslationBtn btnSj) {
        this.btnSj = btnSj;
    }

    public TrslationBtn getBtnCz() {
        return btnCz;
    }

    public void setBtnCz(TrslationBtn btnCz) {
        this.btnCz = btnCz;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public DazaoBtn getPerBtn1() {
        return perBtn1;
    }

    public void setPerBtn1(DazaoBtn perBtn1) {
        this.perBtn1 = perBtn1;
    }

    public RuneOPerBtn getPerBtn2() {
        return perBtn2;
    }

    public void setPerBtn2(RuneOPerBtn perBtn2) {
        this.perBtn2 = perBtn2;
    }

    public goodbtn[] getBtnrights() {
        return btnrights;
    }

    public void setBtnrights(goodbtn[] btnrights) {
        this.btnrights = btnrights;
    }

    public JLabel getLabResult() {
        return labResult;
    }

    public void setLabResult(JLabel labResult) {
        this.labResult = labResult;
    }

    public int getRuneType() {
        return runeType;
    }

    public void setRuneType(int runeType) {
        this.runeType = runeType;
    }

    public ImageIcon getIconBack() {
        return iconBack;
    }

    public void setIconBack(ImageIcon iconBack) {
        this.iconBack = iconBack;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public ImageIcon getIcon2() {
        return icon2;
    }

    public void setIcon2(ImageIcon icon2) {
        this.icon2 = icon2;
    }

    public JLabel[] getGoodsListLabel() {
        return GoodsListLabel;
    }

    public void setGoodsListLabel(JLabel[] goodsListLabel) {
        GoodsListLabel = goodsListLabel;
    }

}
